package com.mall.product.web;

import com.mall.product.dto.CategoryDTO;
import com.mall.product.service.CategoryService;
import com.mall.product.vo.CatelogJsonVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 谢君臣
 * @Date: 2022/7/31-13:19
 * @version: 1.0
 * @function:
 */
@Controller
@Slf4j
public class IndexController {

    @Resource
    private CategoryService categoryService;
    @GetMapping({"/","/index","index.html"})
    public ModelAndView indexPage(){
        log.debug("进入首页页");

        // 获取一级菜单
        List<CategoryDTO> parent = categoryService.listParentCategory();
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("categorys", parent);
        log.debug("" + mav);
        return mav;
    }

    @GetMapping("/index/json/catalog.json")
    @ResponseBody
    public Map<String,List<CatelogJsonVO>> getCatalog(){
        Map<String,List<CatelogJsonVO>> data = categoryService.getCatalogLevel();
        return data;
    }
}
